package com.lavegue.util;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.lavegue.common.Page;
import com.lavegue.dao.ManageMsgDao;
import com.lavegue.model.BisGroup;
import com.lavegue.model.Company;
import com.lavegue.model.ManageMsg;
import com.lavegue.model.Msg;
import com.lavegue.model.UserInfo;
import com.lavegue.service.BisGroupService;
import com.lavegue.service.ManageMsgService;
import com.lavegue.service.MsgService;


/**
 * @author: luoweibin
 * @date:2011-12-19
 * description: 
 *
 */
public class MyBeanFactory {
	//由于j2ee1.4 的xml_api.jar的包与spring冲突
	static {
		System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); 
		System.setProperty("javax.xml.parsers.SAXParserFactory", "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");  
	}
	private static final ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
	private MyBeanFactory() {
	}
	public static final Object getBean(String beanName) {
		return context.getBean(beanName);
	}
	
	public static void main(String[] args) throws Throwable {
//		UserDaoImpl dao = (UserDaoImpl) MyBeanFactory.getBean("userDao");
//		Page<User> page = dao.findPage(3, 30);
//		for (User user : page.getData()) {
//			System.out.println(user.getUserName());
//		}
//	    MsgDao dao = (MsgDao) MyBeanFactory.getBean("msgDao");
//		BisGroupDao gdao = (BisGroupDao) MyBeanFactory.getBean("bisGroupDao");
//		BisTypeDao tdao = (BisTypeDao) MyBeanFactory.getBean("bisTypeDao");
//		UserInfoDao userDao = (UserInfoDao) MyBeanFactory.getBean("userInfoDao");
//		Msg msg = new Msg();
//		msg.setSendTime(new Date());
//		msg.setGroup(gdao.findById(13));
//		msg.setType(tdao.findById(2));
//		msg.setTitle("测试。。。4555");
//		msg.setSender(userDao.findById(1));
//		
//		MsgDetail d1 = new MsgDetail();
//		MsgDetail d2 = new MsgDetail();
//		MsgDetail d3 = new MsgDetail();
//		MsgDetail d4 = new MsgDetail();
//		d1.setMsg(msg);
//		d2.setMsg(msg);
//		d3.setMsg(msg);
//		d4.setMsg(msg);
//		d1.setInter(1);
//		d2.setInter(2);
//		d3.setInter(3);
//		d4.setInter(4);
//		d1.setZhenNo(1);
//		d2.setZhenNo(2);
//		d3.setZhenNo(3);
//		d4.setZhenNo(4);
//		d1.setTxt("one3");
//		d2.setTxt("two3");
//		d3.setTxt("three3");
//		d4.setTxt("four3");
//		List<MsgDetail> ds = new ArrayList<MsgDetail>();
//		ds.add(d1);
//		ds.add(d2);
//		ds.add(d3);
//		ds.add(d4);
//		msg.setMsgDetails(ds);
//		dao.save(msg);
		
		//dao.deleteById(15);
		
//		ManageMsgService s = (ManageMsgService) MyBeanFactory.getBean("manageMsgService");
//		Page<ManageMsg> page = s.findPageByTypeAndGroup(2,14, 1, 10);
//		System.out.println(page.getTotalRecord());
//		BisTypeService b = (BisTypeService) MyBeanFactory.getBean("bisTypeService");
//		List<BisType> all = b.findAll();
//		
//		BisGroupService b = (BisGroupService) MyBeanFactory.getBean("bisGroupService");
//		List<BisGroup> all = b.findAll();
		//for (BisGroup t : all) {
//		for (BisType t : all) {
//			System.out.println(t.getName());
//			if (t.getManageMsgs() != null) {
//				for (ManageMsg m : t.getManageMsgs()) {
//					System.out.println(m.getTitle());
//				}
//			}
//			System.out.println("---------------------------------");
//		}
//		
		BisGroupService d = (BisGroupService) MyBeanFactory.getBean("bisGroupService");
		BisGroup g = d.findById(54);
		d.delete(g);
		System.out.println(111);
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
